namespace TrackSystem.IO.Utils
{
    /// <summary>
    /// 海康网络设备SDK类
    /// </summary>
    public class PTZCamControl
    {
        private string str;
        private string ip, user, password;
        private int port;
        private int lChannel;
        int CamId;// 实例对象id

        public PTZCamControl(string ip, int port, string user, string password)
        {
            this.ip = ip;
            this.port = port;
            this.user = user;
            this.password = password;
            this.CamId = 0;
            PTZWrapper.HI_SDK_Init();
        }
        public bool login()
        {
            try
            {
                //bool set_overtime = HCNetSDK.NET_DVR_SetRecvTimeOut(5000);
                //登录设备 Login the device
                int ptr = 0;
                CamId = PTZWrapper.HI_SDK_LoginExt(ip, user, password, (ushort)port, 1000, ref ptr);
                if (CamId == 0)
                {
                    Console.WriteLine(ip + ": Login fail");
                    PTZWrapper.HI_SDK_Cleanup();
                    return false;
                }
                else
                {
                    //登录成功
                    Console.WriteLine(ip + ": Login Success!");
                    return true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }
        public bool logout()
        {
            if (CamId >= 0)
            {
                //注销登录 Logout the device
                PTZWrapper.HI_SDK_Logout(CamId);
                return true;
            }
            return false;
        }

        public void CamControl(uint code, uint step, uint nSpeed)
        {
            if (step == 0)      // 连续模式
            {
                PTZWrapper.HI_SDK_PTZControl(CamId, (uint)code, nSpeed);
            }
            else
            {
                PTZWrapper.HI_SDK_PTZControlEx(CamId, (uint)code);
            }
        }
    }
}

